<?php

/**
 * This is the model class for table "persona".
 *
 * The followings are the available columns in table 'persona':
 * @property integer $id
 * @property string $nombre
 * @property string $apellidopaterno
 * @property string $apellidomaterno
 * @property string $dni
 * @property integer $incidente
 * @property integer $participacion
 *
 * The followings are the available model relations:
 * @property Participacion $participacion0
 * @property Incidente $incidente0
 */
class Persona extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Persona the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'persona';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nombre, apellidopaterno, apellidomaterno, dni, incidente, participacion', 'required'),
			array('incidente, participacion', 'numerical', 'integerOnly'=>true),
			array('nombre, apellidopaterno, apellidomaterno', 'length', 'max'=>100),
			array('dni', 'length', 'max'=>8),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, nombre, apellidopaterno, apellidomaterno, dni, incidente, participacion', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'participacion0' => array(self::BELONGS_TO, 'Participacion', 'participacion'),
			'incidente0' => array(self::BELONGS_TO, 'Incidente', 'incidente'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'nombre' => 'Nombre',
			'apellidopaterno' => 'Apellidopaterno',
			'apellidomaterno' => 'Apellidomaterno',
			'dni' => 'Dni',
			'incidente' => 'Incidente',
			'participacion' => 'Participacion',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('nombre',$this->nombre,true);
		$criteria->compare('apellidopaterno',$this->apellidopaterno,true);
		$criteria->compare('apellidomaterno',$this->apellidomaterno,true);
		$criteria->compare('dni',$this->dni,true);
		$criteria->compare('incidente',$this->incidente);
		$criteria->compare('participacion',$this->participacion);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}